//
//  SDHSportsTeamDataCell.m
//  SDHSportsNews
//
//  Created by MichaelShan on 2021/3/9.
//

#import "SDHSportsTeamDataCell.h"
#import "SDHSportsPlayerModel.h"
#import "UIImageView+YQAdd.h"

const static CGFloat kLeftViewHeight = 100;
const static CGFloat kLeftViewWidth = 75;
const static CGFloat kAvatarWidth = 50;
const static CGFloat kTextFontSize = 15;

@interface SDHSportsTeamDataCell ()

@property (nonatomic, strong) UIImageView *avatarImg;
@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *birthLb;
@property (nonatomic, strong) UILabel *preferredLb;
@property (nonatomic, strong) UILabel *positionLb;

@end

@implementation SDHSportsTeamDataCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor blackColor];
        UIView *leftView = [UIView new];
        leftView.backgroundColor = [UIColor whiteColor];
        leftView.clipsToBounds = YES;
        leftView.layer.cornerRadius = 5;
        [self.contentView addSubview:leftView];
        
        UIImageView *avatarImg = [UIImageView new];
        avatarImg.image = [UIImage imageNamed:@"touxiang"];
        [leftView addSubview:avatarImg];
        self.avatarImg = avatarImg;
        
        UILabel *nameLb = [UILabel new];
        nameLb.textColor = [UIColor blackColor];
        nameLb.textAlignment = NSTextAlignmentCenter;
        nameLb.numberOfLines = 0;
//        nameLb.backgroundColor = [UIColor redColor];
        [leftView addSubview:nameLb];
        self.nameLb = nameLb;
        nameLb.text = @"Marcus Rashford";
        
        __weak typeof(self) weakSelf = self;
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).offset(20);
            make.top.equalTo(weakSelf.contentView).offset(5);
            make.width.equalTo(@(kLeftViewWidth));
            make.height.equalTo(@(kLeftViewHeight));
        }];
        
        [avatarImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(leftView).offset(5);
            make.centerX.equalTo(leftView);
            make.width.equalTo(@(kAvatarWidth));
            make.height.equalTo(@(kAvatarWidth));
        }];
        
        [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(avatarImg.mas_bottom).offset(5);
            make.centerX.equalTo(avatarImg);
            make.left.equalTo(avatarImg).offset(-10);
            make.right.equalTo(avatarImg).offset(10);
        }];
        
        UIView *rightView = [UIView new];
        rightView.backgroundColor = UIColorFromRGB(81, 81, 81);
        rightView.clipsToBounds = YES;
        rightView.layer.cornerRadius = 5;
        [self.contentView insertSubview:rightView belowSubview:leftView];
        
        UILabel *birthLb = [UILabel new];
        birthLb.textColor = [UIColor whiteColor];
        birthLb.textAlignment = NSTextAlignmentLeft;
        birthLb.font = [UIFont systemFontOfSize:kTextFontSize];
        birthLb.text = @"Date of Birth: 1997-01-01";
        [rightView addSubview:birthLb];
        self.birthLb = birthLb;
        
        UILabel *preferredLb = [UILabel new];
        preferredLb.textColor = [UIColor whiteColor];
        preferredLb.textAlignment = NSTextAlignmentLeft;
        preferredLb.font = [UIFont systemFontOfSize:kTextFontSize];
        preferredLb.text = @"Preferred foot: right foot";
        [rightView addSubview:preferredLb];
        self.preferredLb = preferredLb;
        
        UILabel *positionLb = [UILabel new];
        positionLb.textColor = [UIColor whiteColor];
        positionLb.textAlignment = NSTextAlignmentLeft;
        positionLb.font = [UIFont systemFontOfSize:kTextFontSize];
        positionLb.text = @"Position: Forward";
        [rightView addSubview:positionLb];
        self.positionLb = positionLb;
        
        [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(leftView.mas_right).offset(-5);
            make.top.equalTo(leftView).offset(5);
            make.bottom.equalTo(leftView).offset(-5);
            make.right.equalTo(weakSelf.contentView).offset(-15);
        }];
        
//        [birthLb mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(preferredLb);
//            make.right.equalTo(preferredLb);
//            make.bottom.equalTo(preferredLb.mas_top).offset(-5);
//        }];
//
//        [preferredLb mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(rightView).offset(15);
//            make.centerY.equalTo(rightView);
//            make.right.equalTo(rightView).offset(-5);
//        }];
        
        [positionLb mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(preferredLb);
//            make.right.equalTo(preferredLb);
//            make.top.equalTo(preferredLb.mas_bottom).offset(5);
            make.centerY.equalTo(self.contentView);
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
        }];
    }
    
    return self;
}

- (void)updateContent:(id)obj {
    SDHSportsPlayerModel *player = (SDHSportsPlayerModel *)obj;
    
    [_avatarImg setImageWithURL:[NSURL URLWithString:player.img] placeholderImage:[UIImage imageNamed:@"touxiang"]];
    _nameLb.text = player.en_name;
    _birthLb.hidden = YES;
    _preferredLb.hidden = YES;
    
    _positionLb.text = player.data;
//    _birthLb.text = [NSString stringWithFormat:@"Date of Birth: %@", player.birth_date];
//    _preferredLb.text = [NSString stringWithFormat:@"Salary: %@", player.salary];
//    _positionLb.text = [NSString stringWithFormat:@"Position: %@", player.position];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
